//
//  XSJStatusRetweetView.swift
//  weiBo项目准备
//
//  Created by 鲜世杰 on 16/5/14.
//  Copyright © 2016年 鲜世杰. All rights reserved.
//

import UIKit
import SnapKit
class XSJStatusRetweetView: UIView {

    var retweetViewBottom : Constraint?
    
    var statusViewModel : XSJStatusViewModel?{
    
        didSet {
            contentLabel.attributedText = statusViewModel?.retweetAttributedString

//            contentLabel.text = statusViewModel?.retweetContent
//  pictureView.picUrls = statusViewModel?.status?.retweeted_status?.pic_urls

        retweetViewBottom?.uninstall()
            if let picUrls = statusViewModel?.status?.retweeted_status?.pic_urls where picUrls.count > 0{
                pictureView.hidden = false
                pictureView.picUrls = picUrls
                self.snp_updateConstraints(closure: { (make) -> Void in
                self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin).constraint
                
                })
            }else{
            
                pictureView.hidden = true
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.retweetViewBottom = make.bottom.equalTo(contentLabel).offset(StatusTableViewCellMargin).constraint
                })
                
            }
        }
        
    }
    
    private lazy var contentLabel : UILabel = {
    
//        let label = UILabel(textColor: UIColor.grayColor(), fontSize: 14)
        let label = UILabel(textColor: UIColor.grayColor(), fontSize: HomeFontSize)

        label.numberOfLines = 0
        label.text = "哈哈"
        return label
    
    }()
    
    private lazy var pictureView : XSJStatusPictureView = {
    
       let view = XSJStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
        
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI () {
    
        self.backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(StatusTableViewCellMargin)
            make.top.equalTo(self).offset(StatusTableViewCellMargin)
            make.trailing.equalTo(self).offset(-StatusTableViewCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusTableViewCellMargin)
            make.leading.equalTo(contentLabel)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        self.snp_makeConstraints { (make) -> Void in
//            make.bottom.equalTo(contentLabel).offset(StatusTableViewCellMargin)
//            make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin)
            self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin).constraint
        }
    }
    
    
}
